package com.ruoyi.common.utils;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;

import java.util.HashMap;

public class SplitUtil {

    public static HashMap<String,String> getValue(String input){
        if(!input.contains("url")){
            return new HashMap<>();
        }

        HashMap<String, String> resultMap = new HashMap<>();

        String tString = input.trim();
        String[] rString = tString.split("请求参数")[0].split("返回信息:");
        String url = rString[0].split("url:")[1];
        String rStr1 = rString[1];

        JSONObject jsonObject = JSON.parseObject(rStr1);
        String code = jsonObject.get("code").toString();
        String msg = jsonObject.get("msg").toString();
        JSONObject jsonObject2 = jsonObject.getJSONObject("obj");
//        JSONObject jsonObject2 = JSON.parseObject(jsonObject.get("obj").toString());
        String batchId = jsonObject2.get("batchId").toString();
        String totalCount = jsonObject2.get("totalCount").toString();
        String errorCount = jsonObject2.get("errorCount").toString();

        resultMap.put("url",url);
        resultMap.put("code",code);
        resultMap.put("msg",msg);
        resultMap.put("batchId",batchId);
        resultMap.put("totalCount",totalCount);
        resultMap.put("errorCount",errorCount);
        return resultMap;
    }

}
